﻿using System;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Tasks;


namespace WhallaToolkit.FeedbackControl
{
    public partial class FeedbackPage
    {
        private string emailAddress = string.Empty;
        private string applicationName = string.Empty;
        private IApplicationBarIconButton sendButton;

        public FeedbackPage()
        {
            InitializeComponent();
        }

        private void SendEmailExecute(object sender, EventArgs e)
        {
            EmailComposeTask emailTask = new EmailComposeTask();
            emailTask.To = emailAddress;
            emailTask.Subject = "Feedback";
            emailTask.Body = _PART_FeedbackData.Text;

            emailTask.Show();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (NavigationContext.QueryString.ContainsKey("emailAddress"))
                emailAddress = NavigationContext.QueryString["emailAddress"];

            if (NavigationContext.QueryString.ContainsKey("appName"))
            {
                applicationName = NavigationContext.QueryString["appName"];
                _PART_ApplicationName.Text = applicationName;
            }

            sendButton = (ApplicationBar.Buttons[0] as IApplicationBarIconButton);

            base.OnNavigatedTo(e);
        }

        private void _PART_FeedbackData_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
        {
            if (string.IsNullOrEmpty(_PART_FeedbackData.Text) || string.IsNullOrWhiteSpace(_PART_FeedbackData.Text))
                sendButton.IsEnabled = false;
            else
            {
                sendButton.IsEnabled = true;
            }
        }
    }
}